package com.xiaoc.bulldozer.facade.impl;

import com.xc.framework.common.exception.BusinessException;
import com.xiaoc.bulldozer.common.Constant;
import com.xiaoc.bulldozer.common.ResponseCode;
import com.xiaoc.bulldozer.common.dto.WeixinUserDto;
import com.xiaoc.bulldozer.common.model.Award;
import com.xiaoc.bulldozer.common.model.AwardPartner;
import com.xiaoc.bulldozer.common.service.AwardPartnerService;
import com.xiaoc.bulldozer.common.service.AwardProductService;
import com.xiaoc.bulldozer.facade.AwardFacade;
import com.xiaoc.bulldozer.facade.LikeFacade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("likeFacade")
public class LikeFacadeImpl implements LikeFacade {

    Logger logger = LoggerFactory.getLogger(LikeFacadeImpl.class);


    @Resource(name = "awardPartnerService")
    private AwardPartnerService awardPartnerService;

    @Resource(name = "awardProductService")
    private AwardProductService awardProductService;


    @Override
    public void addLike(WeixinUserDto weixinUserDto, Award award, Integer parentUserId) {

        long currentTime = System.currentTimeMillis();

        if (award == null) {
            logger.error("用户不存在");
            throw new BusinessException(ResponseCode.WEIXIN_USER_NOTEXIST.getCode(), ResponseCode.WEIXIN_USER_NOTEXIST.getMsg());
        }

        AwardPartner awardPartnerForSave = new AwardPartner();
        awardPartnerForSave.setAwardId(award.getId());
        awardPartnerForSave.setUserId(parentUserId);
        awardPartnerForSave.setPaternUserId(weixinUserDto.getId());
        awardPartnerForSave.setPaternRegistStatus(Constant.DISABLE);
        awardPartnerForSave.setUpdateTime(currentTime);
        awardPartnerForSave.setCreateTime(currentTime);
        awardPartnerService.save(awardPartnerForSave);
       // 达到点赞要求 更新红包状态
    }
}
